package com.example.musicapi.dao;

import com.example.musicapi.entity.Record;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RecordDao  extends JpaRepository<Record, String> {

    Record findDataById(String id);

    Page<Record> findAll(Pageable pageable);

    Page<Record> findAllById(Pageable pageable, String id);


    //  根据 key 进行查询的分页方法
    @Query("SELECT n FROM Record n WHERE n.user = :key")
    Page<Record> findBySearch(@Param("key")  String key, Pageable pageable);

//    @Query("SELECT n FROM Record n WHERE n.user = :key  "  )
//    List<Record> findByUser(@Param("key")  String key );


    @Query(value = "SELECT * FROM record2 WHERE user = :key ORDER BY id DESC  LIMIT 80", nativeQuery = true)
    List<Record> findByUser(@Param("key")  String key );
}
